package com.modbus.tool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.modbus.tool.common.Result;
import com.modbus.tool.entity.dto.CollectedDataVO;
import com.modbus.tool.entity.vo.CollectedDataDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.modbus.tool.service.ICollectedDataService;
import com.modbus.tool.entity.po.CollectedData;

import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: Leno
 * @Date: 2025-08-07
 * @Description: collectedData接口
 */
@RequiredArgsConstructor
@Slf4j
@Tag(name = "collectedData接口")
@RestController
@RequestMapping("/collected-data")
public class CollectedDataController {

    private final ICollectedDataService collectedDataService;

    @Operation(summary = "查询所有CollectedData")
    @GetMapping
    public Result<List<CollectedData>> findAll() {
        return Result.success(collectedDataService.list());
    }

    @Operation(summary = "根据id查询CollectedData")
    @GetMapping("/{id}")
    public Result<CollectedData> findOne(@PathVariable Long id) {
        return Result.success(collectedDataService.getById(id));
    }

    @Operation(summary = "根据分页查询CollectedData")
    @GetMapping("/page")
    public Result<Page<CollectedData>> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize,
                                                CollectedData collectedData) {
        return collectedDataService.findPage(pageNum, pageSize, collectedData);
    }

    @Operation(summary = "添加或修改CollectedData")
    @PostMapping
    public Result<Boolean> save(@RequestBody CollectedData collectedData) {
        return Result.success(collectedDataService.saveOrUpdate(collectedData));
    }

    @Operation(summary = "根据id批量删除CollectedData")
    @DeleteMapping("/del/batch")
    public Result<String> deleteBatch(@RequestBody List<Long> ids) {
        return collectedDataService.deleteBatch(ids);
    }

    @Operation(summary = "根据分页查询CollectedDataVO")
    @GetMapping("/page/vo")
    public Result<Page<CollectedDataVO>> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize,
                                                  CollectedDataDTO dto) {
        return collectedDataService.findPage(pageNum, pageSize, dto);
//        return null;
    }

}
